<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>[[${title}]]</h1>
<h2 th:text="${title}"></h2>
<ul>
    <li th:text="${user.username}"></li>
    <li th:text="${user['password']}"></li>
    <li>[[${user.age}]]</li>
    <li th:each="role : ${user.roles}">[[${role}]]</li>
</ul>
<hr>
<h2 th:object="${user}">
    <span th:text="*{username}"></span>
    <span th:text="*{age}"></span>
    <span th:text="*{password}"></span>
</h2>
<hr>
<ul th:each="permission : ${user.permissions.split(';')}">
    <li th:text="${permission}"></li>
</ul>
<hr>
<ul>
<!--    <li th:text="${#ctx}"></li>-->
    <li th:text="${#request}"></li>
    <li th:text="${#response}"></li>
    <li th:text="${#session}"></li>
    <li th:text="${#servletContext}"></li>
</ul>
<hr>
<h3 th:text="${#dates.format(user.createTime, 'yyyy-MM-dd hh:mm:ss')}"></h3>
<hr>
<h3 th:text="'字符串字面值'"></h3>
<hr>
<p>今年是：<span th:text="2020"></span></p>
<p>两年后：<span th:text="2020+2"></span></p>
<hr>
<div th:if="1==1">
    为true
</div>
<hr>
<h3>方法拼接</h3>
<span th:text="'欢迎你：' + ${user.username} + '!'"></span>
<span th:text="|你的密码是:${user.password}|"></span>
<hr>
<h3>运算</h3>
<h4>算数运算</h4>
<span th:text="${user.age}"></span>
<span th:text="${user.age}%2==0"></span>
<span th:text="${user.age}*2"></span>
<h4>比较运算</h4>
<!--== 和!=不仅可以比较数值，而且还可以有类似于equals的功能-->
<span th:text="${user.age}==10"></span>
<span th:text="${user.age} gt 10"></span>
<h4>三元运算</h4>
<span th:text="${user.age}%2==0?'男':'女'"></span>
<!--当前面的值为null时，使用后面的值 ?:之间没有空格 -->
<span th:text="${user.gender} ?: '二狗'"></span>
<h3>循环</h3>
<tr th:each="role,stat : ${user.roles}">
    <th th:text="${stat.index}"></th>
    <th th:text="${role}"></th>
    <br>
</tr>
<h3>逻辑判断</h3>
<span th:if="${user.age} > 20">老油条</span>
<span th:unless="${user.age} < 20">小油条</span>
<h3>分支控制</h3>
<div th:switch="${user.identity}">
    <p th:case="'程序员'">用户是程序员</p>
    <p th:case="'老湿'">用户是老师</p>
    <p th:case="*">用户是别的身份</p>
</div>
<p></p>
<!--获取session中数据-->
<!--<p th:text="${session.sessionKey}"></p>-->

<script th:inline="javascript">
    /*js模板*/
    var user = [[${user}]];
    var age = [[${user.age}]];
    /*获取项目路径*/
    var ctxPath = /*[[@{/}]]*/'';
    console.log(ctxPath);
    console.log(user);
    console.log(user.age);
    console.log(age);

    console.log('-----------------users-----------------')
    const users = [[${users}]];
    console.log(users)
    console.log(users.length)
    users.forEach(user => console.log(user))
</script>
</body>
</html>